import { FormOption } from '@/types/form-common';
import React from 'react';
import FormItem from '../FormItem';
import OneRadio from '../OneRadio';
import classes from './index.module.css';

interface SelectedRadioInf<T> {
  options: FormOption<T>[];
  label?: string;
  value?: T;
  onChange?: (val: T) => void;
}

export default function SelectRadios<T>({
  options,
  label,
  value,
  onChange,
}: SelectedRadioInf<T>) {
  return (
    <FormItem label={label}>
      <div className={classes.SelectRadios}>
        {options.map(option => (
          <OneRadio
            key={option.key}
            label={option.label}
            selected={value === option.value}
            onClick={() => onChange && onChange(option.value)}
          />
        ))}
      </div>
    </FormItem>
  );
}
